package com.ruoyi.student.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import com.ruoyi.college.mapper.AdministrativeClassMapper;
import com.ruoyi.college.mapper.CollegeMapper;
import com.ruoyi.college.service.ICollegeService;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.major.mapper.majorMapper;
import com.ruoyi.student.domain.vo.StudentInfoVo;
import com.ruoyi.student.domain.vo.StudentRegVo;
import com.ruoyi.student.domain.vo.studentDetailedVo;
import com.ruoyi.system.service.impl.SysDeptServiceImpl;
import com.ruoyi.trainingManagement.domain.CourseScheduleDetails;
import com.ruoyi.trainingManagement.domain.CourseStudentInfo;
import com.ruoyi.trainingManagement.domain.TrainingProgramSubject;
import com.ruoyi.trainingManagement.mapper.CourseStudentInfoMapper;
import com.ruoyi.trainingManagement.mapper.TrainingProgramSubjectMapper;
import com.ruoyi.trainingManagement.mapper.trainingProgramMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.student.mapper.StudentInfoMapper;
import com.ruoyi.student.domain.StudentInfo;
import com.ruoyi.student.service.IStudentInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 学生信息管理Service业务层处理
 *
 * @author gdslovehy
 * @date 2025-04-24
 */
@Service
public class StudentInfoServiceImpl implements IStudentInfoService
{
    @Autowired
    private StudentInfoMapper studentInfoMapper;
    @Autowired
    private AdministrativeClassMapper administrativeClassMapper;
    @Autowired
    private CourseStudentInfoMapper courseStudentInfoMapper;
    @Autowired
    private trainingProgramMapper trainingProgramMapper;
    @Autowired
    private CollegeMapper collegeMapper;
    @Autowired
    private majorMapper majorMapper;
    @Autowired
    private TrainingProgramSubjectMapper trainingProgramSubjectMapper;
    //ICollegeService
    @Autowired
    private ICollegeService CollegeService;
    @Autowired
    private SysDeptServiceImpl sysDeptService;

    /**
     * 查询学生信息管理
     * 123456789101112123
     * @param id 学生信息管理主键
     * @return 学生信息管理
     */
    @Override
    public StudentInfo selectStudentInfoById(String id)
    {
        return studentInfoMapper.selectStudentInfoById(id);
    }

    @Override
    public StudentInfo selectStudentInfoByStudentId(String studentId) {
        return studentInfoMapper.selectStudentInfoByStudentId(studentId);
    }

    /**
     * 查询学生信息管理列表
     *
     * @param studentInfo 学生信息管理
     * @return 学生信息管理
     */
    @Override
    public List<StudentInfo> selectStudentInfoList(StudentInfo studentInfo)
    {
        return studentInfoMapper.selectStudentInfoList(studentInfo);
    }
    /**
     * 通过专业ID、学期查询学生信息列表
     */
    @Override
    public List<StudentInfo> selectStudentInfoListByZyAndNj(String student_zy,String student_nj) {
        return studentInfoMapper.selectStudentInfoListByZyAndNj(student_zy,student_nj);
    }
    @Override
    @Transactional // 确保事务管理
    public int assignTrainingToStudents(String trainingProgramId, List<String> studentIds) {
        // 调用Mapper更新学生记录
        System.out.println("service层培养方案IDtrainingProgramId: " + trainingProgramId);
        System.out.println("service层学生信息studentIds: " + studentIds);
        // 创建参数Map
        //统计studentIds学生个数
//        int studentCount = studentIds.size();
//        trainingProgramMapper.updateAmountById(trainingProgramId, studentCount);
        Map<String, Object> params = new HashMap<>();
        params.put("trainingProgramId", trainingProgramId);
        params.put("studentIds", studentIds);
        System.out.println("service层参数params: " + params);
        return studentInfoMapper.updateTrainingProgramForStudents(params);
    }
    /**
     * 新增学生信息管理
     *
     * @param studentInfo 学生信息管理
     * @return 结果
     */
    @Override
    public int insertStudentInfo(StudentInfo studentInfo)
    {
        return studentInfoMapper.insertStudentInfo(studentInfo);
    }

    /**
     * 修改学生信息管理
     *
     * @param studentInfo 学生信息管理
     * @return 结果
     */
    @Override
    public int updateStudentInfo(StudentInfo studentInfo)
    {
        return studentInfoMapper.updateStudentInfo(studentInfo);
    }

    /**
     * 批量删除学生信息管理
     *
     * @param ids 需要删除的学生信息管理主键集合
     * @return 结果
     */
    @Override
    public int deleteStudentInfoByIds(String[] ids)
    {
        return studentInfoMapper.deleteStudentInfoByIds(ids);
    }

    /**
     * 删除学生信息管理信息
     *
     * @param id 学生信息管理主键
     * @return 结果
     */
    @Override
    public int deleteStudentInfoById(String id)
    {
        return studentInfoMapper.deleteStudentInfoById(id);
    }

    /**
     * 传入培养方案列表，遍历列表查询对应的学生列表信息
     */
    @Override
    public List<StudentInfo> selectStudentInfoListByTrainingProgramIds(List<String> trainingProgramId) {
        // 创建最终结果集合
        List<StudentInfo> resultList = new ArrayList<>();
        // 遍历培养方案ID列表
        for (String trainingProgramIdItem : trainingProgramId) {
            // 查询当前培养方案ID对应的学生列表
            List<StudentInfo> studentInfoList = studentInfoMapper.selectStudentInfoListByTrainingProgramId(trainingProgramIdItem);
            // 将查询结果添加到最终集合（防止null）
            if (studentInfoList != null && !studentInfoList.isEmpty()) {
                resultList.addAll(studentInfoList);
            }
        }
        return resultList;
    }
    /*
     * 传入多个学生id以及一个行政班id，批量将学生分配到该行政班，讲行政班ID添加到学生信息表中
     *
     * */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void assignStudentsToClass(String adminClassId, List<String> studentIds) {
        // 1. 批量更新学生表的班级ID
        studentInfoMapper.batchUpdateStudentsToClass(adminClassId, studentIds);

        // 2. 同步更新行政班表的 student_count
        administrativeClassMapper.updateClassStudentCount(adminClassId);
    }

    @Override
    public Map<String, List<CourseStudentInfo>> generateClassList(List<StudentInfo> students, Map<String, Object> data, List<CourseScheduleDetails> allCreatedClasses) {
        System.out.println("打印分班所有数据" + data + "打印排课班级所有数据" + allCreatedClasses + "打印学生所有数据" + students);

        // 用于存储按课程班级分组的结果
        Map<String, List<CourseStudentInfo>> courseStudentMap = new HashMap<>();

        //1.根据获取到的学生名单，统计行政班ID，根据行政班人数从大到小从多到少进行排序
        if (students != null && !students.isEmpty()) {
            // 使用Java 8 Stream API统计班级人数
            Map<String, Long> classStudentCount = students.stream()
                    // 提取班级ID，若为空则使用"未分配班级"作为默认值
                    .map(student -> student.getStudentBj() != null
                            ? student.getStudentBj()
                            : "未分配班级")
                    // 按班级ID分组并统计人数
                    .collect(Collectors.groupingBy(
                            className -> className,
                            Collectors.counting()
                    ));

            // 转换为List并按人数降序排序
            List<Map.Entry<String, Long>> sortedClasses = new ArrayList<>(classStudentCount.entrySet());
            sortedClasses.sort((entry1, entry2) -> entry2.getValue().compareTo(entry1.getValue()));

            // 打印排序结果
            System.out.println("班级人数统计（按人数从多到少排序）：");
            for (Map.Entry<String, Long> entry : sortedClasses) {
                System.out.println("班级：" + entry.getKey() + "，学生人数：" + entry.getValue());
            }

            // 也可以将结果存储到Map中供后续使用
            data.put("classStudentCount", classStudentCount);
            data.put("sortedClasses", sortedClasses);

            //2.根据排序后的结果，将学生进行分组
            if (!allCreatedClasses.isEmpty()) {
                // 获取班级容量（假设所有班级容量相同）
                int classCapacity = Math.toIntExact(allCreatedClasses.get(0).getMaxCapacity());

                // 按行政班分组学生
                Map<String, List<StudentInfo>> studentsByAdminClass = students.stream()
                        .filter(student -> student.getStudentBj() != null)
                        .collect(Collectors.groupingBy(StudentInfo::getStudentBj));

                // 初始化班级分配结果
                Map<String, List<StudentInfo>> classAssignments = new HashMap<>();
                for (CourseScheduleDetails courseClass : allCreatedClasses) {
                    classAssignments.put(courseClass.getId(), new ArrayList<>());
                }

                // 当前处理到的课程班级索引
                int currentClassIndex = 0;
                // 当前课程班级剩余容量
                int remainingCapacity = classCapacity;

                // 遍历每个行政班，按人数从多到少分配
                for (Map.Entry<String, Long> adminClass : sortedClasses) {
                    String adminClassName = adminClass.getKey();
                    long studentCount = adminClass.getValue();

                    // 跳过未分配班级的学生
                    if ("未分配班级".equals(adminClassName)) {
                        continue;
                    }

                    // 获取该行政班的所有学生
                    List<StudentInfo> adminClassStudents = studentsByAdminClass.getOrDefault(adminClassName, Collections.emptyList());

                    // 处理行政班人数超过班级容量的情况
                    if (studentCount > classCapacity) {
                        // 先填满当前班级
                        for (int i = 0; i < classCapacity && i < adminClassStudents.size(); i++) {
                            // 如果当前班级已满，移动到下一个班级
                            if (remainingCapacity <= 0) {
                                currentClassIndex++;
                                if (currentClassIndex >= allCreatedClasses.size()) {
                                    System.out.println("警告：没有足够的课程班级来分配所有学生，剩余学生将被忽略");
                                    break;
                                }
                                remainingCapacity = classCapacity;
                            }

                            // 将学生分配到当前课程班级
                            CourseScheduleDetails currentCourseClass = allCreatedClasses.get(currentClassIndex);
                            classAssignments.get(currentCourseClass.getId()).add(adminClassStudents.get(i));
                            remainingCapacity--;
                        }

                        // 分配剩余学生
                        for (int i = classCapacity; i < adminClassStudents.size(); i++) {
                            // 如果当前班级已满，移动到下一个班级
                            if (remainingCapacity <= 0) {
                                currentClassIndex++;
                                if (currentClassIndex >= allCreatedClasses.size()) {
                                    System.out.println("警告：没有足够的课程班级来分配所有学生，剩余学生：" + (adminClassStudents.size() - i));
                                    break;
                                }
                                remainingCapacity = classCapacity;
                            }

                            CourseScheduleDetails currentCourseClass = allCreatedClasses.get(currentClassIndex);
                            classAssignments.get(currentCourseClass.getId()).add(adminClassStudents.get(i));
                            remainingCapacity--;
                        }
                    } else {
                        // 行政班人数小于等于班级容量，直接分配
                        for (StudentInfo student : adminClassStudents) {
                            // 如果当前班级已满，移动到下一个班级
                            if (remainingCapacity <= 0) {
                                currentClassIndex++;
                                if (currentClassIndex >= allCreatedClasses.size()) {
                                    System.out.println("警告：没有足够的课程班级来分配所有学生，剩余学生：" + student.getStudentId());
                                    break;
                                }
                                remainingCapacity = classCapacity;
                            }

                            CourseScheduleDetails currentCourseClass = allCreatedClasses.get(currentClassIndex);
                            classAssignments.get(currentCourseClass.getId()).add(student);
                            remainingCapacity--;
                        }
                    }
                }

                // 3. 转换为CourseStudentInfo对象并按课程班级分组
                Date now = new Date();
                for (Map.Entry<String, List<StudentInfo>> entry : classAssignments.entrySet()) {
                    String courseClassId = entry.getKey();
                    List<StudentInfo> studentsInClass = entry.getValue();
                    List<CourseStudentInfo> courseStudentList = new ArrayList<>();

                    for (StudentInfo student : studentsInClass) {
                        if (student.getStudentId() != null) {
                            CourseStudentInfo courseStudent = new CourseStudentInfo();
                            courseStudent.setId(IdUtils.fastUUID());
                            courseStudent.setCourseScheduleDetailsId(courseClassId);
                            courseStudent.setStudentId(student.getStudentId());
                            courseStudent.setEnrollmentStatus(1L);
                            courseStudent.setEnrollmentTime(now);
                            courseStudent.setCreatedAt(now);
                            courseStudent.setUpdatedAt(now);
                            courseStudentList.add(courseStudent);
                        }
                    }

                    if (!courseStudentList.isEmpty()) {
                        courseStudentMap.put(courseClassId, courseStudentList);
                    }
                }

                // 将分组结果放入data中返回
                data.put("courseStudentMap", courseStudentMap);
                System.out.println("成功生成 " + courseStudentMap.size() + " 个课程班级的分配记录");
            } else {
                System.out.println("没有可用的课程班级进行分配");
            }
        } else {
            System.out.println("学生名单为空，无法进行班级人数统计");
        }

        // 新增返回语句，返回分组结果
        return courseStudentMap;
    }
    /**
     * 根据硕士类型进行班级分配
     */
    @Override
    public Map<String, List<CourseStudentInfo>> assignStudentsToMasterClass(List<StudentInfo> students, Map<String, Object> data, List<CourseScheduleDetails> allCreatedClasses) {
        System.out.println("打印硕士分班所有数据" + data + "打印排课班级所有数据" + allCreatedClasses + "打印学生所有数据" + students);

        // 用于存储按课程班级分组的结果
        Map<String, List<CourseStudentInfo>> courseStudentMap = new HashMap<>();

        //1.根据获取到的学生名单，统计硕士类型，根据硕士类型进行分组
        if (students != null && !students.isEmpty()) {
            // 使用Java 8 Stream API按硕士类型分组学生
            Map<String, List<StudentInfo>> studentsByMasterType = students.stream()
                    .filter(student -> student.getStudentXwlx() != null)
                    .collect(Collectors.groupingBy(StudentInfo::getStudentXwlx));

            // 打印分组结果
            System.out.println("硕士类型统计：");
            for (Map.Entry<String, List<StudentInfo>> entry : studentsByMasterType.entrySet()) {
                System.out.println("硕士类型：" + entry.getKey() + "，学生人数：" + entry.getValue().size());
            }

            // 也可以将结果存储到Map中供后续使用
            data.put("studentsByMasterType", studentsByMasterType);

            //2.根据分组结果，将每个硕士类型的学生依次分配到班级中
            if (!allCreatedClasses.isEmpty()) {
                // 获取班级容量（假设所有班级容量相同）
                int classCapacity = Math.toIntExact(allCreatedClasses.get(0).getMaxCapacity());

                // 初始化班级分配结果
                Map<String, List<StudentInfo>> classAssignments = new HashMap<>();
                for (CourseScheduleDetails courseClass : allCreatedClasses) {
                    classAssignments.put(courseClass.getId(), new ArrayList<>());
                }

                // 当前处理到的课程班级索引
                int currentClassIndex = 0;
                // 当前课程班级剩余容量
                int remainingCapacity = classCapacity;

                // 遍历每个硕士类型，将学生依次分配到班级
                for (Map.Entry<String, List<StudentInfo>> masterTypeGroup : studentsByMasterType.entrySet()) {
                    String masterType = masterTypeGroup.getKey();
                    List<StudentInfo> studentsInType = masterTypeGroup.getValue();

                    System.out.println("开始分配硕士类型：" + masterType + " 的学生");

                    // 处理该硕士类型的所有学生
                    for (StudentInfo student : studentsInType) {
                        // 如果当前班级已满，移动到下一个班级
                        if (remainingCapacity <= 0) {
                            currentClassIndex++;
                            if (currentClassIndex >= allCreatedClasses.size()) {
                                System.out.println("警告：没有足够的课程班级来分配所有学生，剩余学生：" + student.getStudentId());
                                break;
                            }
                            remainingCapacity = classCapacity;
                        }

                        CourseScheduleDetails currentCourseClass = allCreatedClasses.get(currentClassIndex);
                        classAssignments.get(currentCourseClass.getId()).add(student);
                        remainingCapacity--;
                    }
                }

                // 3. 转换为CourseStudentInfo对象并按课程班级分组
                Date now = new Date();
                for (Map.Entry<String, List<StudentInfo>> entry : classAssignments.entrySet()) {
                    String courseClassId = entry.getKey();
                    List<StudentInfo> studentsInClass = entry.getValue();
                    List<CourseStudentInfo> courseStudentList = new ArrayList<>();

                    for (StudentInfo student : studentsInClass) {
                        if (student.getStudentId() != null) {
                            CourseStudentInfo courseStudent = new CourseStudentInfo();
                            courseStudent.setId(IdUtils.fastUUID());
                            courseStudent.setCourseScheduleDetailsId(courseClassId);
                            courseStudent.setStudentId(student.getStudentId());
                            courseStudent.setEnrollmentStatus(1L);
                            courseStudent.setEnrollmentTime(now);
                            courseStudent.setCreatedAt(now);
                            courseStudent.setUpdatedAt(now);
                            courseStudentList.add(courseStudent);
                        }
                    }

                    if (!courseStudentList.isEmpty()) {
                        courseStudentMap.put(courseClassId, courseStudentList);
                    }
                }

                // 将分组结果放入data中返回
                data.put("courseStudentMap", courseStudentMap);
                System.out.println("成功生成 " + courseStudentMap.size() + " 个课程班级的分配记录");
            } else {
                System.out.println("没有可用的课程班级进行分配");
            }
        } else {
            System.out.println("学生名单为空，无法进行班级人数统计");
        }

        // 返回分组结果
        return courseStudentMap;
    }

    @Override
    public int clearAll() {
        studentInfoMapper.deleteAll();
        return 0;
    }

    /**
     * 将学生分配结果保存到course_student_info表
     */
    @Override
    public void saveCourseStudentAssignments(Map<String, List<CourseStudentInfo>> courseStudentMap) {
        if (courseStudentMap == null) {
            return;
        }

        List<CourseStudentInfo> courseStudentList = new ArrayList<>();
        Date now = new Date();

        // 遍历每个课程班级的分配结果
        for (Map.Entry<String, List<CourseStudentInfo>> entry : courseStudentMap.entrySet()) {
            List<CourseStudentInfo> students = entry.getValue();
            courseStudentList.addAll(students);
        }

        // 批量保存到数据库
        if (!courseStudentList.isEmpty()) {
            courseStudentInfoMapper.batchInsert(courseStudentList);
            System.out.println("成功保存 " + courseStudentList.size() + " 条学生课程分配记录");
        }
    }

    /*根据学生ID获取对应的 studentName;trainingProgramName;collegeName;majorName;*/
    @Override
    public studentDetailedVo getStudentDetailedInfo(String studentId) {
        //打印接受到的参数
        System.out.println("接受到的参数（学生ID）：" + studentId);

        StudentInfo studentInfo =studentInfoMapper.selectStudentInfoById(studentId);
        System.out.println("接受到的参数（学生信息）：" + studentInfo);
        studentDetailedVo studentDetailedVo = new studentDetailedVo();
        String trainingProgramId=studentInfo.getTrainingProgramId();
        String collegeCode = studentInfo.getStudentYx();
        String majorCode = studentInfo.getStudentZy();
        studentDetailedVo.setId(studentInfo.getId());
        studentDetailedVo.setStudentName(studentInfo.getStudentName());
        studentDetailedVo.setTrainingProgramName(trainingProgramMapper.selecttrainingProgramById(trainingProgramId).getName());
        studentDetailedVo.setCollegeName(collegeMapper.selectCollegeByCollegeCode(collegeCode).getCollegeName());
        //studentDetailedVo.setMajorName(majorMapper.selectMajorByMajorCode(majorCode).getMajorName());
        studentDetailedVo.setMajorName(CollegeService.selectCollegeByCollegeCodeAndSubjectCodeAndDirectionCode(studentInfo.getStudentYx(),studentInfo.getStudentZy(),studentInfo.getStudentYjfxm()));
        studentDetailedVo.setStudentId(studentInfo.getStudentId());
        System.out.println("返回的参数（学生姓名;培养计划名称;学院名称;专业名称;学生ID）：" + studentDetailedVo);
        return studentDetailedVo;
    }

    /**
     * 批量插入学生信息
     */
    @Override
    public int batchInsert(List<StudentInfo> studentList) {
        return studentInfoMapper.batchInsert(studentList);
    }

    /*
     *根据培养方案ID查询对应的学科列表，根据列表中的培养方案ID获取对应的学生名单
     */
    @Override
    public List<StudentInfo> selectStudentInfoListByTrainingProgramIdAndSubject(String trainingProgramId) {
        // 初始化结果列表
        List<StudentInfo> students = new ArrayList<>();
        if (trainingProgramId == null || trainingProgramId.trim().isEmpty()) {
            System.out.println("警告：传入的培养方案ID为空");
            return students;
        }

        try {
            // 查询该培养方案下的所有学科
            List<TrainingProgramSubject> subjects = trainingProgramSubjectMapper.selectTrainingProgramSubjectByTrainingProgramId(trainingProgramId);
            System.out.println("培养方案ID[" + trainingProgramId + "]关联的学科数量：" + (subjects != null ? subjects.size() : 0));

            // 避免空指针异常：如果没有学科，直接返回空列表
            if (subjects == null || subjects.isEmpty()) {
                return students;
            }

            // 使用Set去重，避免同一学生被多个学科关联时重复出现
            Set<StudentInfo> studentSet = new HashSet<>();

            for (TrainingProgramSubject subject : subjects) {
                // 处理学科ID为空的情况
                String subjectId = subject.getSubjectId();
                if (subjectId == null || subjectId.trim().isEmpty()) {
                    System.out.println("警告：学科ID为空，跳过该学科");
                    continue;
                }

                // 初始化学生查询条件对象
                StudentInfo queryParam = new StudentInfo();

                // 处理4位学科ID补全逻辑（补全为6位，在末尾加00）
                if (subjectId.length() == 4) {
                    // 4位ID补全规则：在末尾添加"00"（例如：0835 → 083500）
                    String completedZy = subjectId + "00";
                    queryParam.setStudentZy(completedZy);
                    System.out.println("学科ID[" + subjectId + "]补全为：" + completedZy);
                } else {
                    // 非4位ID直接使用原始值
                    queryParam.setStudentZy(subjectId);
                    System.out.println("使用原始学科ID查询：" + subjectId);
                }

                // 设置研究方向ID（已修正拼写错误：Rescarech → Research）
                String researchDirectionId = subject.getRescarechDirectionId();
                queryParam.setStudentYjfxm(researchDirectionId);
                if (researchDirectionId != null) {
                    System.out.println("当前学科关联的研究方向ID：" + researchDirectionId);
                }

                // 根据条件查询学生列表
                List<StudentInfo> studentList = studentInfoMapper.selectStudentInfoListByZyAndYjfxm(queryParam);
                System.out.println("获取到的学生名单"+studentList);
                // 合并到结果集合（自动去重）
                if (studentList != null && !studentList.isEmpty()) {
                    System.out.println("从学科ID[" + subjectId + "]查询到学生数量：" + studentList.size());
                    studentSet.addAll(studentList);
                }
            }

            // 将去重后的结果转为List返回
            students.addAll(studentSet);
            System.out.println("最终去重后的学生总数：" + students.size());

        } catch (Exception e) {
            // 捕获并处理所有异常，避免方法中断
            System.err.println("查询学生列表时发生异常：" + e.getMessage());
            e.printStackTrace();
        }

        return students;
    }

    @Override
    public StudentRegVo getStudentReVoByStudentId(String studentId) {
        return studentInfoMapper.getStudentRegVoByStudentId(studentId);
    }

    @Override
    public List<StudentInfo> selectStudentInfoByStudentIds(ArrayList<String> strings) {
        return studentInfoMapper.selectStudentInfoByStudentIds(strings);

    }
    @Override
    public int updateStudentZcztByStudentId(String studentId, String zczt) {
        // 1. 构建更新对象（仅更新状态和更新时间）
        StudentInfo studentInfo = new StudentInfo();
        studentInfo.setStudentId(studentId); // 学号（唯一标识）
        studentInfo.setStudentZczt(zczt);    // 状态文本（如“已通过”）
        studentInfo.setUpdateTime(new Date());// 更新时间（审计字段）

        // 2. 调用 Mapper 执行更新
        return studentInfoMapper.updateStudentZcztByStudentId(studentInfo);
    }

    @Override
    public StudentInfo getStudentByStudentId(String studentId) {
        return studentInfoMapper.selectStudentInfoByStudentXh(studentId);
    }

    @Override
    public List<StudentInfo> getAllStudentInfoList(StudentInfo studentInfo) {
        return studentInfoMapper.getAllStudentInfoList(studentInfo);
    }

    @Override
    public List<StudentInfoVo> selectStudentInfoVoList(StudentInfoVo studentInfoVo) {
        return studentInfoMapper.selectStudentInfoVoList(studentInfoVo);
    }

    //根据登录用户的信息返回对应的collegeId列表
    @Override
    public List<String> selectCollegeIdsByDeptIds() {
        List<Long> roleDeptIds = sysDeptService.getRoleDeptIds();
        if (CollectionUtils.isEmpty(roleDeptIds)) {
            return new ArrayList<>(); // 返回空列表，避免执行错误SQL
        }
        List<String> collegeId= collegeMapper.selectCollegeIdsByDeptIds(roleDeptIds);
        return collegeId;
    }
    //根据登录用户的信息返回对应的college_code列表
    @Override
    public List<String> selectCollegeCodesByDeptIds() {
        List<Long> roleDeptIds = sysDeptService.getRoleDeptIds();
        if (CollectionUtils.isEmpty(roleDeptIds)) {
            return new ArrayList<>(); // 返回空列表，避免执行错误SQL
        }
        List<String> collegeCodes= collegeMapper.selectCollegeCodesByDeptIds(roleDeptIds);
        return collegeCodes;
    }

    @Override
    public List<StudentInfo> selectStudentIdsByCollegeCodes(List<String> collegeCodes, StudentInfo studentInfo) {
        return studentInfoMapper.selectStudentIdsByCollegeCodes(collegeCodes,studentInfo);
    }

    @Override
    public String selectStudentCollegeCodesByStudentId(String initiatorId) {
        return studentInfoMapper.selectStudentCollegeCodesByStudentId(initiatorId);
    }

}
